package com.Txunda.fxw.ui.adapter.base;

import android.support.v7.widget.RecyclerView;
import android.view.View;


import com.Txunda.fxw.ui.listener.AdapterViewClickListener;
import com.Txunda.fxw.ui.listener.OnItemClickListener;
import com.Txunda.fxw.ui.listener.OnItemLongClickListener;

import butterknife.ButterKnife;

/**
 * 创建时间：2018/11/6 15:11
 * 作    者：Hzj
 * 描    述：RecyclerView的ViewHolder
 * 注    意：
 * 修    改：V2.0
 * 参    考：
 * 出    自：书山府科技_Android
 **/
public abstract class BaseRecyclerViewHolder<T> extends RecyclerView.ViewHolder {
    /**
     * item View点击事件
     */
    public AdapterViewClickListener<T> adapterViewClickListener;
    /**
     * item点击事件
     */
    public OnItemClickListener<T> onItemClickListener;
    /**
     * item长按事件
     */
    public OnItemLongClickListener<T> onItemLongClickListener;

    public BaseRecyclerViewHolder(View itemView) {
        super(itemView);
        ButterKnife.bind(this, itemView);
    }

    public abstract void setData(T item, int position);

    void setAdapterViewClickListener(AdapterViewClickListener<T> adapterViewClickListener) {
        this.adapterViewClickListener = adapterViewClickListener;
    }

    public void setOnItemClickListener(OnItemClickListener<T> onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    void setOnItemLongClickListener(OnItemLongClickListener<T> onItemLongClickListener) {
        this.onItemLongClickListener = onItemLongClickListener;
    }

    void bindItemClickListener(int position, T item) {
        if (onItemClickListener != null)
            onItemClickListener.onClick(itemView, position, item);
        if (onItemLongClickListener != null)
            onItemLongClickListener.onLongClick(itemView, position, item);
    }

    public void setViewOnClick(int position, T item) {
        if (adapterViewClickListener == null)
            throw new NullPointerException("请设置回调监听");
    }
}
